#include <iostream>
#include <tchar.h>
//#include "../IOCPModel/IOCPModel.h"
#include "../logger/Logger.h"
#include "../common/AuxString.h"
#include <string.h>
#include "../common/CpuUsage.h"

#include "../Variant/Variant.h"

#include <algorithm>

#include <comdef.h>
#include <atlbase.h>
#include <queue>
#include <atomic>

#include <boost\thread\thread.hpp>

#pragma  comment(lib,"libboost_thread-vc110-mt-gd-1_51.lib")

#pragma code_seg(["section-name"[,"section-class"]]) 


atomic<int> na21 = 0;
void ThreadFun()
{
	for (int i=0;i<100;i++)
	{
		na21++;
		cout<<na21<<ends;
	}

}
void fun1(int&& i)
{
	int nn = 2;
}

void fun2()
{
	int nn = 2;
	fun1(static_cast<int&&>(nn));
}
void fun3()
{
	void* pRaw = operator new(22);
	operator delete(pRaw);
}

class B
{
public:
	void fun1()
	{
	
	}
	static void* operator new(size_t t,void* p)
	{
		return p;
		//return ::operator new(t);
	}
	operator bool()
	{
		int i = 0;
		i = 8;
		i++;
		return i;
	}
	//bool operator()
	//{		
	//	return false;
	//}
};

void fun4()
{
	char ch[1024];
	int size = sizeof B;
	B* pb = new(ch) B();
	pb->fun1();
	B* pb1 = new(ch + size) B();
	pb1->fun1();


	enum num {a = 1,b,c};
	num x = num(0);

	B b2;
	bool b1 = (bool)b2;
	if(b2)
	{
		int i;
		i = 9;
		i++;
	}


}

void fun5()
{
	stringstream ss;
	cout << boolalpha << true;
	cout << boolalpha << false;
	cout << boolalpha << true;
	cout << true;
	cout << false;
//	cout << showbase << hex << 0x535465;
	cout << hex <<  showbase << 0x535465;

	string str = ss.str();

	std::locale::global(std::locale(""));

	basic_fstream<char> ff;
	locale loc("chs");
	fstream fs("1.txt",fstream::out);
	ofstream of("out.txt");
	bool b = fs.is_open();
	bool b1 = of.is_open();
	cout.rdbuf(of.rdbuf());
	cout << 343434 << "fdsfdf" << 23.323 << flush;
	fs << 32 <<"fdddddddddddddddddddddddddddddd";
//	streambuf sbuf;
	fs.close();
	of.close();
}

int _tmain(int argc, _TCHAR* argv[])
{
	CLogger::Ins();

	MSGHUB_LOG("fsad%sf","123123sf");
	MSGHUB_WARNING("sdfsadf");
	MSGHUB_DEBUG("one","fsadf");
	MSGHUB_ERROR("aaa%d%s%c",200,_T("abc"),'c');


	CLogger::Ins()->logHex(CLogger::_ERROR_,"123abc");

	int nsize = sizeof(long) + sizeof(char) + sizeof(unsigned long) + sizeof(SOCKET);

	//CCpuUsage a;
	//while (true)
	//{
	//	cout<<	a.GetCpuUsage((DWORD)0)<<ends;

	//	Sleep(300);
	//}

// 	std::queue<int >  que;
// 	int n = que.front();
// 	que.pop();

	typedef union _tagValue
	{
		bool b;
		int n;
		double d;

		_tagValue()
		{
			d = 0.256f;
			int nn = sizeof _tagValue;
			memset(&b,0,sizeof _tagValue);
		}
	}_value;

	_value v;
	double dd = v.d;

	int arr[] = {1,2,3,4,5};
	int *a =( int*) (&arr + 1);
	int *b = (int *)(arr + 1);

	int na = a[-1];
// 	Variant var;
// 	var = 42342;
// 	int nnfdf = var;

	atomic<int> na1;
	atomic_long jj;
	int l = sizeof jj;
	
	na1 = 33;

	na1 = 313;
	na1 = 233;
	memory_order_relaxed;

	boost::thread_group thg;
	for (int i = 0;i<10 ;i++)
	{
		thg.create_thread(ThreadFun);
	}
	thg.join_all();


	fun2();
	fun4();
	fun5();
// 	CIOCPModel iocp;
// 	iocp.Start();
// 	for (;;)
// 	{
// 		
// 	}



	ATL::CRegKey regkey;
	TCHAR szValue [1024];
	DWORD dwCount = 512;
	wstring strKeyName = _T("SOFTWARE\\Wow6432Node\\Tencent\\PlatForm_Type_List\\1");
	if (regkey.Open (HKEY_LOCAL_MACHINE,strKeyName.c_str()) == ERROR_SUCCESS)
	{
		if (regkey.QueryValue (szValue, _T("TypePath"), &dwCount) == ERROR_SUCCESS)
		{
			//			TRACE0 ("Query Success.\n");
			//		strTemp = szValue;
			//			SetDlgItemText (IDC_EDIT1, strTemp);
		}
	}


	STARTUPINFOA si = { sizeof(si) };  
	PROCESS_INFORMATION pi;
	CHAR szCommandLine[] = ("NOTEPAD");
//	CHAR szCommandLine1[] = ();
//	BOOL bRet = CreateProcessA("D:\\QQ\\bin\\QQ.exe","",NULL,NULL,false,0,NULL,NULL,&si,&pi);
	int error = GetLastError();  
	return 0;
}
